package com.spring.security.service;

import com.spring.security.dao.SysUserRepository;
import com.spring.security.entity.SysUser;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * ClassName: CumDetailsService
 * Desc:  认证服务
 * Date： 2017/5/26
 * Created：shaom
 */
public class CumDetailsService implements UserDetailsService {
    @Resource
    SysUserRepository sysUserRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser byUsername = sysUserRepository.findByUsername(username);
        if (Objects.isNull(byUsername)) {
            throw new UsernameNotFoundException("用户不存在");
        }

        return byUsername;
    }
}
